package com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.task;

import com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.common.SateTraceContext;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Optional;

/**
 * @author gee
 * @since 2025/5/15 15:40
 */
@Slf4j
public class TmArcEndTask extends AbstractHandler implements TimerTask {

    private SateTraceContext sateTraceContext;

    public TmArcEndTask(List<AbstractHandler> delegateTaskList) {
        super(delegateTaskList);
    }

    @Override
    public void run(Timeout timeout) throws Exception {
        log.info("TmArcEndTask run");
        Timeout tmFrameTimeout = sateTraceContext.getTmFrameTimeout();
        Optional.of(tmFrameTimeout).ifPresent(Timeout::cancel);
    }

    @Override
    protected boolean doStart(SateTraceContext sateTraceContext, long simulateTime) {
        log.info("TmArcEndTask doStart");
        this.sateTraceContext = sateTraceContext;
        return true;
    }
}
